<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CC的办公系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
  .ui-datepicker table {
    border: 0;
  }
  .ui-autocomplete-loading { 
    background: white url('images/ui-anim_basic_16x16.gif') left center no-repeat; 
  }
  .ui-autocomplete,.ui-menu-item .ui-corner-all {
      border-radius: 0;
  }
  thead th{
    text-align:center;
    background:#e0e0e0;
  }
  tbody th[scope="row"],tbody th.sub{
    text-align:center;
  }
  input,select{
    border:1px solid #888888;
  }
  .yform input, .yform textarea, .yform select, .yform optgroup {
    font-family:宋体;
  }
  input:hover,input:active,select:hover,select:active{
    border:1px solid #aa6666
  }
  input[type=text]{
    padding:2px;
    margin:1px 0;
  }
  #pagebar{
    float:right;
  }
  #search_bar{
    border-width:1px 0;
  }
  #search_bar td{
    padding:1px;
    border-width:0;
  }
  #search_bar tr:hover td{
    background:#fff;
  }
  .bt_button{
    cursor: pointer;
    overflow: visible;
    width: auto;
    background: url("lib/yaml/screen/images/button_gray.png") repeat-x scroll left top #454545;
    border-color: #DDDDDD #444444 #444444 #DDDDDD;
    border-style: solid;
    border-width: 1px;
    color: #000000;
    padding: 5px 1em;  
  }
  .bt_button:hover,.bt_button:active,.bt_button:focus{
    background: none repeat-x scroll left top #555555;
    border-color: #444444 #DDDDDD #DDDDDD #444444;
    color: #ffffff;
  }
  #page_go,#print_search,.bt_act{
    padding:0;
  }
  .chk{
    background-color:#d0d0d0;
  }
  #diaglog_print{
    display:none;
  }
  #lb_search{
    //width:5em;
  }
  #bts_search{
    width:11.9em;
    text-align:right;
  }
  #adv_search{
    display:none;
  }
</style>
<script type="text/javascript">
  $(function() {
    $("#form1").validationEngine();
    //$(".datepicker").datepicker({ minDate: "-1w", maxDate: 0 });
    $(".datepicker").datepicker({  maxDate: 0 });
    var p=1;
    var search_filter="";
    function vi(p){
      $.get("searchoffer_main.asp?page="+p+search_filter,function(data){  //用ajax的get方式提交
        $("#search_main").html(data);

        $("#pagebar a").click(function(e){  //对分页栏中的a元素进行操作
          e.preventDefault();  //阻止a的原先事件
          vi($(this).attr("id"));  //根据获取的页码值调用显示页面函数
        });
        $("#page_go").click(function(e){  //对分页栏中的input元素进行操作
          e.preventDefault();
          if (isNaN($("#page_val").val())||$.trim($("#page_val").val())==""){  //判断输入的是否是数字
            alert("输入的页码错误，请输入正确页码！");
            $("#page_val").select();
            return false;  //页码值不是数字则退出；
          }
          vi($("#page_val").val());
        });
        var chk=$(".checkid");
        $("#checkall").click(function(){
          chk.prop("checked",$(this).prop("checked"));//根据全选的checkbox状态来填充单个checkbox状态
          $(this).prop("checked") ? chk.closest("tr").addClass("chk") : chk.closest("tr").removeClass("chk")//判断是否全部选中，选中则增加chk样式，没选中则删除chk样式，不能用toggleClass方法，由于下面单个checkbox会改变全选的checkbox状态
        });
        chk.click(function(){
          if(!$(this).prop("checked")) $("#checkall").prop("checked",false);//如果当前checkbox状态为未选中则全选的checkbox也设置为未选中
          $(this).closest("tr").toggleClass("chk");//单个切换当前checkbox存在的tr的chk样式
        });
        
        $("#delid").click(function(){
          $chks=$("#search_main input:checkbox.checkid:checked");
          if(confirm("要删除这 "+$chks.length+" 条记录吗？")){
            var aChk=new Array();
            $chks.each(function(){
              aChk.push($(this).val());
            });
            $.post("deloffer.asp",{chks:aChk.join(),act:$("#delid").val()},function(data){
              if(data.bStatus){
                alert("删除成功！");
                vi($("#page_val").val());
              }else{
                alert(data.sInfo);
              }
            },"json");
          }
        });
        
      });

    }
    
    Init_Empe($("#offer_dept").val());
    function Init_Empe(dept_id){
      Get_Empe(dept_id);
      Gen_Search_Filter();
    }
    Init_Goods($("#goods_class").val());
    function Init_Goods(goods_class){
      Get_Goods(goods_class);
      Gen_Search_Filter();
    }
    
    vi(p);
    var Json_Goods;
    function Get_Goods(goods_class){
      $.getJSON("json_goods.asp?goods_class="+goods_class,function(data){
        Json_Goods=data;
        var goods_name_option='<option value="0">'+FillSpace('批号',6)+FillSpace('文具名',20)+FillSpace('规格',10)+FillSpace('库存',6)+'</option>';
        $.each(Json_Goods,function(i,item){
          goods_name_option+='<option value="'+item.goods_id+'">'+FillSpace(item.goods_purchase,6)+FillSpace(item.goods_name,20)+FillSpace(item.goods_spec,10)+FillSpace(item.goods_stock,6)+'</option>';
        });
        $("#goods_name").html(goods_name_option);
      });
    }
    function Get_Goods_Info(goods_id){
      if(goods_id=="0"){
        $("#goods_info").html("");
      }else{
        $.each(Json_Goods,function(i,item){
          if(item.goods_id==goods_id){
            $("#goods_id,#offer_goods").val(item.goods_id);
            $("#goods_stock").val(item.goods_stock);
            //$("#offer_quantity").val(item.goods_stock);
            $("#goods_unitprice").val(item.goods_unitprice);
            goods_info="";
            goods_info+="文具批号：<span>"+item.goods_purchase+"</span>&nbsp;";
            goods_info+="文具名：<span>"+item.goods_name+"</span>&nbsp;";
            goods_info+="型号：<span>"+item.goods_model+"</span>&nbsp;";
            goods_info+="规格：<span>"+item.goods_spec+"</span>&nbsp;";
            goods_info+="品牌：<span>"+item.brand_name+"</span>&nbsp;";
            goods_info+="单价：<span>"+item.goods_unitprice+"</span>&nbsp;";
            goods_info+="库存：<span>"+item.goods_stock+"</span>&nbsp;";
            goods_info+="<span>"+item.unit_name+"</span>&nbsp;";
            goods_info+="备注：<span>"+item.goods_memo+"</span>&nbsp;";
            $("#goods_info").html(goods_info);
            $("#offer_quantity").attr("class","validate[required,custom[integerNz],max["+item.goods_stock+"]]");
            return false;
          };
        });
      }
    }
    $("#goods_class").change(function(){
      $("#goods_name").html('<option value="0">选择文具名</option>');
      Gen_Search_Filter();
      $("#goods_info").html("");
      if($(this).val()!="0"){
        Get_Goods($(this).val());
      }
      vi(p);
    });
    $("#goods_name").change(function(){
      Get_Goods_Info($(this).val());
      Gen_Search_Filter();
      vi(p);
    });
    
    $("#form1").submit(function(){
      if($("#offer_dept").val()==0){
        alert("请选择部门");
        $("#offer_dept").focus();
        return false;
      }
      //alert($("#goods_class").val());
      if($("#goods_class").val()==0){
        alert("请选择分类");
        $("#goods_class").focus();
        return false;
      }
      if($("#goods_name").val()==0){
        alert("请选择文具名");
        $("#goods_name").focus();
        return false;
      }
      if($("#offer_empe").val()==0){
        var c=confirm("未选择员工，计入部门领用，确定吗？");
        if(!c){
          $("#offer_empe").focus();
          return false;
        }
      }
    });
    $("#offer_dept").change(function(){
      $("#offer_empe").html('<option value="0">选择员工</option>');
      Gen_Search_Filter();
      Get_Empe($(this).val());
      vi(p);
    });
    $("#offer_empe").change(function(){
      Gen_Search_Filter();
      vi(p);
    });
    function Gen_Search_Filter(){
      var d=$("#offer_dept").val();
      var e=$("#offer_empe").val();
      var c=$("#goods_class").val();
      var n=$("#goods_name").val();
      if(d=="0"&&c=="0"){
        search_filter="";
      }else{
        if(d=="0"){
          if(n=="0"){
            search_filter="&class_id="+c;
          }else{
            search_filter="&class_id="+c+"&goods_id="+n;
          }
        }else{
          if(c=="0"){
            if(e=="0"){
              search_filter="&offer_dept="+d;
            }else{
              search_filter="&offer_dept="+d+"&offer_empe="+e;
            }
          }else{
            if(e=="0"){
              if(n=="0"){
                search_filter="&offer_dept="+d+"&class_id="+c;
              }else{
                search_filter="&offer_dept="+d+"&class_id="+c+"&goods_id="+n;
              }
            }else{
              if(n=="0"){
                search_filter="&offer_dept="+d+"&offer_empe="+e+"&class_id="+c;
              }else{
                search_filter="&offer_dept="+d+"&offer_empe="+e+"&class_id="+c+"&goods_id="+n;
              }
            }
          }
        }
      }
    }
    
    
    function Get_Empe(dept_id){
      $.getJSON("json_getempe.asp?dept_id="+dept_id,function(data){
        var empe_name_option='<option value="0">选择员工</option>';
        $.each(data,function(i,item){
          if($("#old_empe").val()==item.empe_id){
            empe_name_option+='<option value="'+item.empe_id+'" selected="selected">'+item.empe_name+'</option>';
          }else{
            empe_name_option+='<option value="'+item.empe_id+'">'+item.empe_name+'</option>';
          }
        });
        $("#offer_empe").html(empe_name_option);
      });
    }
  });
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),3,5) then call JumpErrorPage(2)
submit=saferequest("submit",0)
offer_dept=saferequest("offer_dept",1)
offer_empe=saferequest("offer_empe",1)
goods_class=saferequest("goods_class",1)
If submit<>"" Then
  conn.BeginTrans
  goods_id=saferequest("goods_id",1)
  offer_goods=saferequest("offer_goods",1)
  offer_quantity=cdbl(saferequest("offer_quantity",1))
  goods_stock=cdbl(saferequest("goods_stock",1))
  goods_unitprice=cdbl(saferequest("goods_unitprice",1))
  ' offer_price=offer_quantity*goods_unitprice
  offer_date=saferequest("offer_date",0)
  offer_memo=saferequest("offer_memo",0)
  offer_operator=session("iId")
  offer_update=now()
  if submit="新增" and goods_stock>=offer_quantity then
    if offer_empe=0 then
      sql="insert into offer(offer_goods,offer_dept,offer_quantity,offer_date,offer_memo,offer_operator) values("&goods_id&","&offer_dept&","&offer_quantity&",'"&offer_date&"','"&offer_memo&"',"&offer_operator&")"
    else
      sql="insert into offer(offer_goods,offer_dept,offer_empe,offer_quantity,offer_date,offer_memo,offer_operator) values("&goods_id&","&offer_dept&","&offer_empe&","&offer_quantity&",'"&offer_date&"','"&offer_memo&"',"&offer_operator&")"
    end if
    ' response.write sql
    ' response.end
    offer_id=ExecuteCommand(sql,true)
  end if
  if err.number=0 then 
    conn.CommitTrans  '如果没有conn错误，则执行事务提交
  else
    conn.RollbackTrans '否则回滚
    '回滚后的其他操作
    'strerr=err.Description
    url=request.ServerVariables("http_host")&request.ServerVariables("url")
    Response.Write "数据库错误！<br /><font color=red>Error # " & CStr(Err.Number) & "<br />" & Err.Description & "<br />Source: " & Err.Source &"<br />错误页面："&url&"</font><br />"
    Response.End
  end if
end if

%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
  <div id="col3" role="main">
    <div id="col3_content" class="clearfix">
      <form id="form1" name="form1" method="post" class="yform" role="application">
  领用日期：  <input type="text" class="datepicker validate[required]" size="10" readonly="readonly" name="offer_date" id="offer_date" value="<%=date()%>" />
          <select id="offer_dept" name="offer_dept">
            <option value="0">选择部门</option>
          <%
            Set rs_dept = Server.CreateObject("ADODB.Recordset")
            sql_dept = "SELECT * FROM dept order by dept_name"
            rs_dept.Open sql_dept,conn,1,1
            do while not rs_dept.eof
          %>
            <option value="<%=rs_dept("dept_id")%>" <%if rs_dept("dept_id")=clng(offer_dept) then response.write("selected='selected'")%>><%=rs_dept("dept_name")%></option>
          <%
              rs_dept.movenext
            loop
            rs_dept.close
            set rs_dept=nothing
          %>
          </select>
          <select id="offer_empe" name="offer_empe">
            <option value="0">选择员工</option>
          </select>
          <input type="hidden" id="old_empe" name="old_empe" value="<%=offer_empe%>" />
          <select id="goods_class" name="goods_class" class="validate[required]">
            <option value="0">选择分类</option>
          <%
            Set rs_goods = Server.CreateObject("ADODB.Recordset")
            sql_class = "SELECT * FROM class order by class_name"
            rs_goods.Open sql_class,conn,1,1
            do while not rs_goods.eof
          %>
            <option value="<%=rs_goods("class_id")%>" <%if rs_goods("class_id")=clng(goods_class) then response.write("selected='selected'")%>><%=rs_goods("class_name")%></option>
          <%
              rs_goods.movenext
            loop
            rs_goods.close
            set rs_goods=nothing
          %>
          </select>
          <select id="goods_name" name="goods_name" class="validate[required]">
            <option value="0">选择文具名</option>
          </select>
  数量：  <input type="text" class="validate[required,custom[integerNz]]" name="offer_quantity" size="4" id="offer_quantity" />
  备注：  <input type="text" name="offer_memo" id="offer_memo" />
          <input type="hidden" name="offer_goods" id="offer_goods" />
          <input type="hidden" name="goods_id" id="goods_id" />
          <input type="hidden" name="goods_unitprice" id="goods_unitprice" />
          <input type="hidden" name="goods_stock" id="goods_stock" />
          <input type="submit" name="submit" id="submit_add" value="新增" />
          <input type="reset" name="reset" value="重置" />
      </form>
      <div id="goods_info">
      </div>
      <div id="search_main"></div>
    </div>
  </div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

